<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>How to Determine the Kind of a Number From std::numeric_limits</title>
<link rel="stylesheet" href="../../../multiprecision.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
<link rel="up" href="../limits.html" title="Numeric Limits">
<link rel="prev" href="limits32.html" title="Numeric limits for 32-bit platform">
<link rel="next" href="../input_output.html" title="Input Output">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="limits32.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../limits.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../input_output.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_multiprecision.tut.limits.how_to_tell"></a><a class="link" href="how_to_tell.html" title="How to Determine the Kind of a Number From std::numeric_limits">How to
        Determine the Kind of a Number From <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code></a>
</h4></div></div></div>
<p>
          Based on the information above, one can see that different kinds of numbers
          can be differentiated based on the information stored in <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>. This is in addition to
          the traits class <a class="link" href="../../ref/number.html#boost_multiprecision.ref.number.traits_class_support">number_category</a>
          provided by this library.
        </p>
<h5>
<a name="boost_multiprecision.tut.limits.how_to_tell.h0"></a>
          <span class="phrase"><a name="boost_multiprecision.tut.limits.how_to_tell.integer_types"></a></span><a class="link" href="how_to_tell.html#boost_multiprecision.tut.limits.how_to_tell.integer_types">Integer
          Types</a>
        </h5>
<p>
          For an integer type T, all of the following conditions hold:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_specialized</span> <span class="special">==</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_integer</span> <span class="special">==</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_exact</span> <span class="special">==</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">min_exponent</span> <span class="special">==</span> <span class="number">0</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max_exponent</span> <span class="special">==</span> <span class="number">0</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">min_exponent10</span> <span class="special">==</span> <span class="number">0</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max_exponent10</span> <span class="special">==</span> <span class="number">0</span>
</pre>
<p>
          In addition the type is <span class="emphasis"><em>signed</em></span> if:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_signed</span> <span class="special">==</span> <span class="keyword">true</span>
</pre>
<p>
          If the type is arbitrary precision then:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_bounded</span> <span class="special">==</span> <span class="keyword">false</span>
</pre>
<p>
          Otherwise the type is bounded, and returns a non zero value from:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max</span><span class="special">()</span>
</pre>
<p>
          and has:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_modulo</span> <span class="special">==</span> <span class="keyword">true</span>
</pre>
<p>
          if the type implements modulo arithmetic on overflow.
        </p>
<h5>
<a name="boost_multiprecision.tut.limits.how_to_tell.h1"></a>
          <span class="phrase"><a name="boost_multiprecision.tut.limits.how_to_tell.rational_types"></a></span><a class="link" href="how_to_tell.html#boost_multiprecision.tut.limits.how_to_tell.rational_types">Rational
          Types</a>
        </h5>
<p>
          Rational types are just like integers except that:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_integer</span> <span class="special">==</span> <span class="keyword">false</span>
</pre>
<h5>
<a name="boost_multiprecision.tut.limits.how_to_tell.h2"></a>
          <span class="phrase"><a name="boost_multiprecision.tut.limits.how_to_tell.fixed_precision_types"></a></span><a class="link" href="how_to_tell.html#boost_multiprecision.tut.limits.how_to_tell.fixed_precision_types">Fixed
          Precision Types</a>
        </h5>
<p>
          There appears to be no way to tell these apart from rational types, unless
          they set:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_exact</span> <span class="special">==</span> <span class="keyword">false</span>
</pre>
<p>
          This is because these types are in essence a rational type with a fixed
          denominator.
        </p>
<h5>
<a name="boost_multiprecision.tut.limits.how_to_tell.h3"></a>
          <span class="phrase"><a name="boost_multiprecision.tut.limits.how_to_tell.floating_point_types"></a></span><a class="link" href="how_to_tell.html#boost_multiprecision.tut.limits.how_to_tell.floating_point_types">floating-point
          Types</a>
        </h5>
<p>
          For a floating-point type T, all of the following conditions hold:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_specialized</span> <span class="special">==</span> <span class="keyword">true</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_integer</span> <span class="special">==</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_exact</span> <span class="special">==</span> <span class="keyword">false</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">min_exponent</span> <span class="special">!=</span> <span class="number">0</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max_exponent</span> <span class="special">!=</span> <span class="number">0</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">min_exponent10</span> <span class="special">!=</span> <span class="number">0</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">max_exponent10</span> <span class="special">!=</span> <span class="number">0</span>
</pre>
<p>
          In addition the type is <span class="emphasis"><em>signed</em></span> if:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_signed</span> <span class="special">==</span> <span class="keyword">true</span>
</pre>
<p>
          And the type may be decimal or binary depending on the value of:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">radix</span>
</pre>
<p>
          In general, there are no arbitrary precision floating-point types, and
          so:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_bounded</span> <span class="special">==</span> <span class="keyword">false</span>
</pre>
<h5>
<a name="boost_multiprecision.tut.limits.how_to_tell.h4"></a>
          <span class="phrase"><a name="boost_multiprecision.tut.limits.how_to_tell.exact_floating_point_types"></a></span><a class="link" href="how_to_tell.html#boost_multiprecision.tut.limits.how_to_tell.exact_floating_point_types">Exact
          floating-point Types</a>
        </h5>
<p>
          Exact floating-point types are a <a href="http://en.wikipedia.org/wiki/Field_%28mathematics%29" target="_top">field</a>
          composed of an arbitrary precision integer scaled by an exponent. Such
          types have no division operator and are the same as floating-point types
          except:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">is_exact</span> <span class="special">==</span> <span class="keyword">true</span>
</pre>
<h5>
<a name="boost_multiprecision.tut.limits.how_to_tell.h5"></a>
          <span class="phrase"><a name="boost_multiprecision.tut.limits.how_to_tell.complex_numbers"></a></span><a class="link" href="how_to_tell.html#boost_multiprecision.tut.limits.how_to_tell.complex_numbers">Complex
          Numbers</a>
        </h5>
<p>
          For historical reasons, complex numbers do not specialize <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code>, instead you must inspect
          <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">&gt;</span></code>.
        </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2002-2020 John
      Maddock and Christopher Kormanyos<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="limits32.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../limits.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../input_output.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
